<%@ page isErrorPage="true" %>
<%@ page import="com.actimind.actitime.beans.UserBean,
                 com.actimind.actitime.Keys,
                 java.io.ByteArrayOutputStream,
                 java.io.PrintStream,
                 java.sql.SQLException"%><%
%>
<%@ taglib uri="/WEB-INF/at.tld" prefix="at" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%
    if (exception != null)
    {
        // if this jsp page is called from another jsp
        session.setAttribute( Keys.ERROR_KEY, exception);
    }

    Throwable e = ( Throwable ) session.getAttribute( Keys.ERROR_KEY );
    if( e == null )
        return;
%>
<%!
    public String StackTraceToString(Throwable e)
    {
        ByteArrayOutputStream buf = new ByteArrayOutputStream(300);
        PrintStream pStream = new PrintStream(buf);
        e.printStackTrace(pStream);
        return buf.toString();
    }

    public String prepareErrorMessage(Throwable e)
    {
        StringBuffer buf = new StringBuffer();
        if (e instanceof SQLException)
        {
            SQLException ex = (SQLException)e;
            if (ex.getMessage().indexOf("ODBC") >= 0) // MS Access: err_code = 0
            {
                buf.append("Error connecting to database.<br/>\n")
                   .append("Possible reason: ODBC data source does not exist.");
            }
            else if (ex.getErrorCode() == 1049) // MySQL:
            {
                buf.append("Error connecting to database.<br/>\n")
                   .append("Possible reason: Database does not exist.");
            }
            else
            {
                buf.append("Error connecting to database.<br/>\n")
                   .append("Possible reason: Database does not exist.");
            }
        }
        else
        {
            buf.append("Error has occured when processing the last action.");
            if(e instanceof IllegalArgumentException)
                buf.append("<br/>Possible reason: Incorrect JDK version is used.");

        }
        return buf.toString();
    }
%>
<!--
<%=StackTraceToString(e)%>
-->
<html>
<head>
    <title>Error</title>

    <link rel="stylesheet" href="<html:rewrite page='/css/at.css'/>" type="text/css">
</head>

<body bgcolor="#ffffff" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">

<%
UserBean user = (UserBean)session.getAttribute(Keys.LOGGEDIN_USER_KEY);
if (user != null)
{
%>
<%-- User is logged in --%>
<jsp:include page="top.jsp" flush="false">
    <jsp:param name="pageSection" value="error" />
    <jsp:param name="pageAction" value="" />
</jsp:include>

<br />
<table cellspacing="0" cellpadding="5" align="center" valign="top" border="0" bgcolor="#ffffff" width="770">
<tr>
    <td class="pagetitle">Error</td>
</tr>
<tr>
    <td class="pagetitle">
        <span class="errormsg"><%=prepareErrorMessage(e)%></span>
    </td>
</tr>
</table>
<%
}
else
{
%>
<%-- User not logged in --%>
<table width="100%" height="100%" cellspacing="0" cellpadding="0" align="center" valign="middle" border="0" bgcolor="#ffffff">
<tr>
    <td><html:img page="/img/pixel.gif" height="100" width="1"/></td>
</tr>
<tr>
    <td align="center">
        <table width="460" cellspacing="0" cellpadding="0" align="center" border="0" bgcolor="#18409D">
        <tr>
            <td colspan="3"><html:img height="30" width="1" page="/img/pixel.gif"/></td>
        </tr>
        <tr>
            <td class="logintitle" colspan="3" align="center">Intelligent Time Tracking Identification and efficient billing management Software Login</td>
        </tr>
        <tr>
            <td colspan="3"><html:img height="80" width="1" page="img/pixel.gif"/></td>
        </tr>
        <tr>
            <td><html:img height="1" width="40" page="/img/pixel.gif"/></td>
            <td class="errormsg" valign="top"><center><%=prepareErrorMessage(e)%></center></td>
            <td><html:img height="1" width="40" page="/img/pixel.gif"/></td>
        </tr>
        <tr>
            <td colspan="3"><html:img height="80" page="/img/pixel.gif"/></td>
        </tr>
        </table>
    </td>
</tr>
<tr>
    <td><html:img page="/img/pixel.gif" height="100" width="1"/></td>
</tr>
<tr>
    <td align="center" valign="bottom" height="44">
        <table height="24" cellspacing="0" cellpadding="0" align="center" valign="middle" border="0" bgcolor="#ffffff">
        <tr>
            <td align="right" valign="top">
                <html:img page="/img/small_logo.gif" width="24" height="24"/>
            </td>
            <td>
                <html:img height="24" width="10" page="/img/pixel.gif"/>
            </td>
            <td align="left" valign="top" class="copyright">
                &copy; Intelligent Time Tracking Identification and efficient billing management Softwarex, Inc. 2011<br>
                
            </td>
        </tr>
        <tr>
            <td colspan="3">
                <html:img height="20" width="1" page="/img/pixel.gif"/>
            </td>
        </table>
    </td>
</tr>
</table>
<%
}
%>
<%--Clear errors--%>
<at:errors />

</body>
</html>
